cmake_minimum_required(VERSION 2.8)
project(exiv2)
file(GLOB lib_srcs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/*.cpp)
file(GLOB lib2_srcs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} xmpsdk/src/*.cpp)
file(GLOB lib_hdrs include/*)
set(CMAKE_DEBUG_POSTFIX "D")
list(REMOVE_ITEM lib_srcs src/utils.cpp src/getopt.cpp src/exiv2.cpp src/actions.cpp)
list(REMOVE_ITEM lib2_srcs utils.cpp getopt.cpp exiv2.cpp actions.cpp)
list(APPEND lib_libs ${ZLIB_LIBRARIES} ${ICONV_LIBRARIES} ${EXPAT_LIBRARIES} ws2_32 psapi)
include_directories(${CMAKE_CURRENT_SOURCE_DIR} include xmpsdk/include ${ZLIB_INCLUDE_DIRS} ${ICONV_INCLUDE_DIRS} ${EXPAT_INCLUDE_DIRS})
add_definitions(/Dexiv2lib_EXPORTS /DNOMINMAX)
add_library(${PROJECT_NAME} SHARED ${lib_srcs} ${lib2_srcs} ${lib_hdrs})
target_link_libraries(${PROJECT_NAME} ${lib_libs})
install(FILES ${lib_hdrs} DESTINATION include/${PROJECT_NAME})
install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}-targets RUNTIME DESTINATION bin ARCHIVE DESTINATION lib)
install(EXPORT ${PROJECT_NAME}-targets DESTINATION lib/cmake FILE ${PROJECT_NAME}-config.cmake)

if(BUILD_STATIC)
  add_library(${PROJECT_NAME}S STATIC ${lib_srcs} ${lib2_srcs} ${lib_hdrs})
  install(TARGETS ${PROJECT_NAME}S EXPORT ${PROJECT_NAME}S-targets RUNTIME DESTINATION bin ARCHIVE DESTINATION lib)
  install(EXPORT ${PROJECT_NAME}S-targets DESTINATION lib/cmake FILE ${PROJECT_NAME}S-config.cmake)
endif()
